package cc.realxyq.demo.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

/**
 * 自定义加载规则的过滤器
 * @author kwhan
 * @date 2022年01月07日 7:26
 */
@Slf4j
public class CustomTypeFilter implements TypeFilter {
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) {
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        Resource resource = metadataReader.getResource();
        log.warn("类的元数据：{},注解的元数据：{},Resource:{}",classMetadata,annotationMetadata,resource);

        // 任何类名中包含er的类都会被注入
        return classMetadata.getClassName().contains("er");
    }
}
